package com.yvtian.admin.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yvtian.admin.pojo.SysDept;
import com.yvtian.admin.pojo.SysRole;
import com.yvtian.admin.pojo.SysUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户(SysUser)表数据库访问层
 *
 * @author long
 */
@Configuration("userDao")
public interface SysUserDao extends BaseMapper<SysUser> {
//
//    @Select("select * from sys_user where username = #{name} and is_delete=0")
//    SysUser selectByName(@Param("name") String username);

    @Select("select * from sys_user where account = #{account} and is_delete = 0")
    SysUser selectByAccess(@Param("account") String account);

    SysUser selectUserInfo(String id);

    @Update("update sys_user set is_delete = 1 where id in(#{ids})")
    int delUsers(@Param("ids") String ids);

    /**
     * 根据用户Id查询角色
     * @param userId 用户Id
     */
    @Select("select * from sys_role where id in(" +
            "select role_id from sys_user_role where user_id = #{userId}" +
            ")")
    ArrayList<SysRole> findRoleByUserId(@Param("userId")String userId);

    IPage<SysUser> findUserByPage(@Param("page") Page<SysUser> page, @Param("sysUser") SysUser sysUser, List<Integer> deptIds);

}
